package com.ruoyi.service.impl;

import java.util.List;

import com.ruoyi.annotation.AddOrUpdateFilter;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.domain.TCertificateDocument;
import com.ruoyi.domain.TCertificateDocumentAttachment;
import com.ruoyi.domain.THonorAttchment;
import com.ruoyi.service.ITCertificateDocumentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.mapper.TCertificateDocumentMapper;
import com.ruoyi.domain.TCertificateDocument;
import com.ruoyi.service.ITCertificateDocumentService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 证件信息Service业务层处理
 *
 * @author ruoyi
 * @date 2024-11-04
 */
@Service
@Slf4j
public class TCertificateDocumentServiceImpl implements ITCertificateDocumentService {
    @Autowired
    private TCertificateDocumentMapper tCertificateDocumentMapper;
    @Autowired
    private TCertificateDocumentAttachment tCertificateDocumentAttachment;


    /**
     * 查询证件信息
     *
     * @param id 证件信息主键
     * @return 证件信息
     */
    @Override
    public List<TCertificateDocument> selectTCertificateDocumentById(Long id) {
        List<TCertificateDocument> tCertificateDocuments = tCertificateDocumentMapper.selectTCertificateDocumentById(id);
        return tCertificateDocuments;
    }

    /**
     * 根据证件id查询证件信息
     *
     * @param certificateId 证件信息主键
     * @return 证件信息
     */
    @Override
    public TCertificateDocument selectByIdCertificateId(Long certificateId) {
        TCertificateDocument tCertificateDocument = tCertificateDocumentMapper.selectByIdCertificateId(certificateId);
        return tCertificateDocument;
    }

    /**
     * 查询荣誉信息附件
     *
     * @param certificateId 证件信息主键
     * @return 荣誉信息
     */
    @Override
    public List<TCertificateDocument> selectAttachmentById(Long certificateId) {

        return tCertificateDocumentMapper.selectAttachmentById(certificateId);
    }

    /**
     * 查询证件信息列表
     *
     * @param tCertificateDocument 证件信息
     * @return 证件信息
     */
    @Override
    public List<TCertificateDocument> selectTCertificateDocumentList(TCertificateDocument tCertificateDocument) {
        return tCertificateDocumentMapper.selectTCertificateDocumentList(tCertificateDocument);
    }

    /**
     * 新增证件信息
     *
     * @param tCertificateDocument 证件信息
     * @return 结果
     */

    @Transactional
    @Override
    public int insertTCertificateDocument(TCertificateDocument tCertificateDocument) {
        tCertificateDocumentMapper.insertTCertificateDocument(tCertificateDocument);
        List<String> attachs = tCertificateDocument.getAttachs();
        Long certificateDocumentId = tCertificateDocument.getId();
        if (attachs != null && !attachs.isEmpty()) {
            attachs.forEach(attach -> {
                // 附件路径
                tCertificateDocumentAttachment.setAttach(attach);
                tCertificateDocumentAttachment.setCertificateDocumentId(certificateDocumentId);

                // 附件上传路径
                tCertificateDocumentMapper.insertDocumentAttach(tCertificateDocumentAttachment);
            });

        }
        return 1;
    }

    /**
     * 修改证件信息
     *
     * @param tCertificateDocument 证件信息
     * @return 结果
     */

    @Override
    public int updateTCertificateDocument(TCertificateDocument tCertificateDocument) {
        tCertificateDocument.setUpdateTime(DateUtils.getNowDate());
        return tCertificateDocumentMapper.updateTCertificateDocument(tCertificateDocument);
    }

    /**
     * 批量删除证件信息
     *
     * @param ids 需要删除的证件信息主键
     * @return 结果
     */
    @Override
    public int deleteTCertificateDocumentByIds(Long[] ids) {
        return tCertificateDocumentMapper.deleteTCertificateDocumentByIds(ids);
    }

    /**
     * 删除证件信息信息
     *
     * @param id 证件信息主键
     * @return 结果
     */
    @Override
    public int deleteTCertificateDocumentById(Long id) {
        return tCertificateDocumentMapper.deleteTCertificateDocumentById(id);
    }
}
